package com.ck.task.springtask;

import com.ck.common.BaseTask;
import com.ck.common.annotation.TaskLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author ck
 * @date 2023/2/27 8:37
 */
@Component
@Slf4j
public class SpringTask extends BaseTask {
    @Value("${task.testTask01.enable}")
    private Boolean enabled;



    @TaskLog
    @Scheduled(cron = "${task.testTask01.cron}")
    public void task1() throws InterruptedException {
        if (!enabled) {
            return;
        }
        long start = taskStart();
        System.err.println("task1执行定时任务");
        Thread.sleep(5000);
        taskEnd(start);
    }


    @Value("${task.testTask02.enable}")
    private Boolean enabled1;
    @TaskLog
    @Scheduled(cron ="${task.testTask02.cron}")
    public void task2(){
        if (!enabled1){
            return;
        }
        long start = taskStart();
        System.err.println("task2执行定时任务");
        taskEnd(start);
    }

}
